package ar.edu.unq.wannaplay.utils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;

import ar.edu.unq.wannaplay.employee.Employee;

public class SortManager {

    public static List<Pair<Employee, Float>> sortPairListBySecond(final List<Pair<Employee, Float>> pairList) {
        Comparator<Pair<Employee, Float>> comparator = new Comparator<Pair<Employee, Float>>() {
            @Override
            public int compare(final Pair<Employee, Float> p1, final Pair<Employee, Float> p2) {
                return p1.getSecond() == p2.getSecond() ? 0 : p1.getSecond() < p2.getSecond() ? 1 : -1;
            }
        };

        Queue<Pair<Employee, Float>> queue = new PriorityQueue<Pair<Employee, Float>>(pairList.size(), comparator);
        queue.addAll(pairList);

        List<Pair<Employee, Float>> orderedPairList = new ArrayList<Pair<Employee, Float>>();

        while (!queue.isEmpty()) {
            orderedPairList.add(queue.poll());
        }

        return orderedPairList;
    }
}
